import { Role } from './../models';
import { paraMap, paramMapByArr } from './../utils';

export default {
    findById(id: string) {
        return Role.findById(id);
    },
    create(param: object | any) {
        const role = new Role();
        paraMap(param, role);
        return role.save();
    },
    update(param: object | any) {
        const _param: any = paramMapByArr(param, ['role_name', 'mids', 'apis', 'memo', 'status']);
        _param.update_at = Date.now();
        return Role.update({ _id: param.id }, _param);
    },
    remove(id: string) {
        return Role.deleteOne({ _id: id });
    },
    find(param: object | any) {
        const _para: any = paramMapByArr(param, ['role_name', 'status']);
        return Role.find(_para).limit(param.page_size).skip(param.page_no - 1);
    }
};